﻿#region LicenseHeader

// Copyright 2012 The Trustees of Indiana University.  All rights reserved.
// 
// The Indiana University licenses this file to you under the Apache License, 
// Version 2.0 (the "License"); you may not use this file except in compliance 
// with the License.  You may obtain a copy of the License at 
// 
// http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software 
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
//  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
// See the License for the specific language governing permissions and 
// limitations under the License.
// 
// @author Thilina Gunarathne (tgunarat@indiana.edu)

#endregion

#region

using AzureMRCore.DataTypes;
using AzureMRCore.InputFormat;
using AzureMRCore.MapRed;
using AzureMRCore.OutputFormat;

#endregion

namespace AzureMRCore.Drivers
{
    public abstract class MapReduceDriver<TMapInKey, TMapInValue, TMapOutKey, TMapOutValue, TReduceOutKey,
                                          TReduceOutValue> :MRDriver
        where TMapInKey : Key, new()
        where TMapInValue : IValue, new()
        where TMapOutKey : Key, new()
        where TMapOutValue : IValue, new()
        where TReduceOutKey : Key, new()
        where TReduceOutValue : IValue, new()
    {
        /* Required Configuration properties */
        public abstract Mapper<TMapInKey, TMapInValue, TMapOutKey, TMapOutValue, NullKey, NullValue> MapperType { get; }
        public abstract IInputFormat<TMapInKey, TMapInValue> InputFormatType { get; }
        public abstract Reducer<TMapOutKey, TMapOutValue, TReduceOutKey, TReduceOutValue> ReducerType { get; }

        /* optional configuration properties */

        public virtual IOutputFormat<TMapOutKey, TMapOutValue> MapOutputFormatType
        {
            get { return new SequenceOutputFormat<TMapOutKey, TMapOutValue>(); }
        }

        public virtual IOutputFormat<TReduceOutKey, TReduceOutValue> ReduceOutputFormatType
        {
            get { return new SequenceOutputFormat<TReduceOutKey, TReduceOutValue>(); }
        }

        public virtual Reducer<TMapOutKey, TMapOutValue, TMapOutKey, TMapOutValue> CombinerType
        {
            get { return null; }
        }

        #region MRDriver_proxies

        public override sealed IMapper GetMapper()
        {
            return MapperType;
        }

        public override sealed IReducer GetReducer()
        {
            return ReducerType;
        }

        public override sealed IReducer GetCombiner()
        {
            return CombinerType;
        }

        public override sealed IInputFormat<K, V> GetInputFormat<K, V>()
        {
            return (IInputFormat<K, V>) InputFormatType;
        }

        public override sealed IOutputFormat<K, V> GetMapOutputFormat<K, V>()
        {
            return (IOutputFormat<K, V>) MapOutputFormatType;
        }

        public override sealed IOutputFormat<K, V> GetReduceOutputFormat<K, V>()
        {
            return (IOutputFormat<K, V>) ReduceOutputFormatType;
        }

        #endregion

        /* non-generic proxy methods to use by the MRDriver */
    }
}